unit _fmMain;

interface

uses
  WaitFreeMemoryPool, SimpleThread,
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TfmMain = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    FMemoryPool : TWaitFreeMemoryPool;
    FThreads : array [0..16] of TSimpleThread;
    procedure on_ThreadExcute(Sender:TObject);
  public
  end;

var
  fmMain: TfmMain;

implementation

{$R *.dfm}

procedure TfmMain.FormCreate(Sender: TObject);
var
  Loop: Integer;
begin
  FMemoryPool := TWaitFreeMemoryPool.Create(1024);

  for Loop := 0 to POOL_LIST_COUNT-1 do
    FMemoryPool.SetMemoryPoolSize(Loop, 64*1024*1024 div MEMORY_SIZES[Loop]);

//  FMemoryPool.SetMemoryPoolSize(3, 64*1024*1024 div MEMORY_SIZES[3]);
//  FMemoryPool.SetMemoryPoolSize(4, 64*1024*1024 div MEMORY_SIZES[4]);
//  FMemoryPool.SetMemoryPoolSize(5, 64*1024*1024 div MEMORY_SIZES[5]);

  for Loop := Low(FThreads) to High(FThreads) do FThreads[Loop] := TSimpleThread.Create(on_ThreadExcute);
end;

procedure TfmMain.on_ThreadExcute(Sender: TObject);
var
  iCount : integer;
  Data : pointer;
begin
  iCount := 0;
  while not TSimpleThread(Sender).Terminated do begin
    FMemoryPool.GetMem(Data, Random($FFFF + $FF));

    Inc(iCount);
    if iCount > $FFFFFF then Break;
  end;
end;

end.
